package controller.admin;

import javafx.fxml.FXML;
import javafx.scene.control.Alert;


import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import sql.JDBC_T;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.MessageFormat;


public class AdminAddTeacherController {
    @FXML
    private TextField adm_teacheradd_tf_tid;
    @FXML
    private TextField adm_teacheradd_tf_troom;
    @FXML
    private TextField adm_teacheradd_tf_tname;
    @FXML
    private RadioButton adm_teacheradd_rb_male;
    public void addtea(){
        Alert alert = new Alert(Alert.AlertType.WARNING);
        String tid,tname,tsex,toffice;
        tid = adm_teacheradd_tf_tid.getText();
        tname =adm_teacheradd_tf_tname.getText();
        toffice=adm_teacheradd_tf_troom.getText();
        if(adm_teacheradd_rb_male.isSelected()){
            tsex = "男";
        }else {
            tsex = "女";
        }
        String sql = MessageFormat.format("Insert into   teacher values ({0}{1}{0},{0}{2}{0},{0}{3}{0},{0}{4}{0},{0}{5}{0})","'",tid,toffice,tname,"123123",tsex);
        JDBC_T jdbc_t = new JDBC_T();
        if(jdbc_t.is_conn()){
            try{
                PreparedStatement preparedStatement = jdbc_t.getConn().prepareStatement(sql);
                System.out.println(sql);
                preparedStatement.execute(sql);
                alert= new Alert(Alert.AlertType.INFORMATION);
                alert.setContentText("注册成功!!!");
                alert.showAndWait();
            }catch (SQLException sqlException){
                alert= new Alert(Alert.AlertType.WARNING);
                alert.setContentText("插入数据表失败!!!请检查后重新插入");
                alert.showAndWait();
            }

        }

    }

}


